package cn.uniqueinfo.dp.service.impl;

import cn.uniqueinfo.dp.mapper.BizMapper;
import cn.uniqueinfo.dp.service.IBizService;
import cn.uniqueinfo.dp.service.base.BaseServiceImpl;
import cn.uniqueinfo.dp.vo.EasyuiTableResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author:朱元勋
 * @mail:395910063@qq.com
 * @date:2019-01-10 16:12:30
 * @description:
 */
@Service
@Slf4j
public class BizServiceImpl extends BaseServiceImpl implements IBizService {

    @Autowired private SqlSessionFactory sqlSessionFactory;

    private BizMapper bizMapper;

    public BizServiceImpl(BizMapper bizMapper) {
        this.bizMapper = bizMapper;
        this.baseMapper = bizMapper;
    }

    @Override
    public EasyuiTableResult dynamicSql(HashMap param, Integer pageNum, Integer pageSize) {
        EasyuiTableResult result = new EasyuiTableResult();
        PageHelper.startPage(pageNum, pageSize, true);
        List list = this.bizMapper.dynamicSql(param);
        PageInfo pageInfo = new PageInfo(list);
        result.setRows(list);
        result.setTotal(pageInfo.getTotal());
        return result;
    }

    @Override
    public void insertItem(HashMap param) {
        System.out.println("insert: sql=" + param.get("sql"));
        this.bizMapper.insertItem(param);
    }

    @Override
    public Integer updateItem(HashMap param) {
        System.out.println("update: sql=" + param.get("sql"));
        return this.bizMapper.updateItem(param);
    }

    @Override
    public HashMap getItem(String tableName, Long id) {
        return this.bizMapper.getItem(tableName, id);
    }

    @Override
    public Integer deleteItems(String tableName, String ids) {
        return this.bizMapper.deleteItems(tableName, ids);
    }
}
